/**
 * 判断指定的字符串value是不是手机号<br>
 * 如果是，则返回true；否则返回false<br>
 */
function isMobile(value) {
    return /^[1][3,4,5,7,8][0-9]{9}$/i.test(value);
}

function matchMobile(mobile) {
    return /^[1][3-8][0-9]{9}$/i.test(mobile);
}

function matchPassword(password) {
    return /^([a-z]|[A-Z]|[0-9]|[._]){8,16}$/i.test(password);
}

function isEmail(value) {
    return /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i.test(
        value);
}

/*
 * 校验电话号码
 */
function isPhone(str) {
    var patrn = /^(0[\d]{2,3}-)?\d{6,8}(-\d{3,4})?$/;
    return patrn.test(str);
}

function isValidRoleSum(roleSum) {

	var isValid = true;
	var type = /^[0-9]$/;
    var re = new RegExp(type);
    if (roleSum.match(re) == null) {
    	isValid = false;
    }

    return isValid;
}
Date.prototype.Format = function(fmt) {
    var o = {
        "M+":this.getMonth() + 1,
        // 月份
        "d+":this.getDate(),
        // 日
        "h+":this.getHours(),
        // 小时
        "m+":this.getMinutes(),
        // 分
        "s+":this.getSeconds(),
        // 秒
        "q+":Math.floor((this.getMonth() + 3) / 3),
        // 季度
        S:this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] :("00" + o[k]).substr(("" + o[k]).length));
    return fmt;
};
//日期格式化
function dateFormat(date){
    if(date){
        return (new Date(date)).Format("yyyy-MM-dd");
    }else{
        return "";
    }
}
//日期小时分钟格式化
function dateHoursMinFormat(date){
    if(date){
        return (new Date(date)).Format("yyyy-MM-dd");
    }else{
        return "";
    }
}

//判断设备是移动端或Pc端
function browserRedirect() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    var bIsWx = sUserAgent.match(/MicroMessenger/i) == "micromessenger";
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsWx) {
        return 'MOBILE';
    } else {
        return 'PC';
    }
}

//判断访问终端
var userDevice = (function(){
    var sUserAgent = navigator.userAgent.toLowerCase();
    return{
        isIpad : sUserAgent.match(/ipad/i) == "ipad",
        isIphoneOs : sUserAgent.match(/iphone os/i) == "iphone os",
        isAndroid : sUserAgent.match(/android/i) == "android",
        isWeiXin : sUserAgent.match(/micromessenger/i) == "micromessenger",
        isWeiBo: sUserAgent.match(/weibo/i) == "weibo"
    }
})();

//地址栏请求文件名称
function requestPageName(str){
    var index = str.lastIndexOf("\/");
    str  = str .substring(index + 1, str.length);
    if(str.split("?")[0]){
        str = str.split("?")[0];
    }
    return str;
}

//texarea回车显示
function textareaEnter(string){
    var textarea;
    if(string){
        textarea = string.replace(/\r?\n/g,"<br>");
        return textarea;
    }else{
        return "";
    }
}

//texarea回车显示
function textareaBr(string){
    var textarea;
    if(string){
        textarea = string.replace(/<br\s*\/?>/ig,"\n");
        return textarea;
    }else{
        return "";
    }
}


